package com.ms.action.basic;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eddy.util.AjaxOut;
import com.ms.dao.entity.basic.ResourcesEty;
import com.ms.dao.mapper.basic.ResourcesDao;

/**
 * 用户桌面数据
 * @author Eddy
 *
 */
@Controller
@RequestMapping("/basic/DesktopAction/")
public class DesktopAction {

	@Autowired
	private ResourcesDao resourcesDao;
	
	@RequestMapping("getUserData.action")
	public void getUserData(HttpServletRequest request, HttpServletResponse response) {
		try {
			JSONObject userDataObj = new JSONObject();
			JSONArray modulesArr = new JSONArray();
			List dataList = resourcesDao.selectByEntity(null);
			for(int i = 0; i < dataList.size(); i++) {
				ResourcesEty ety = (ResourcesEty) dataList.get(i);
				
				JSONObject aObj = new JSONObject();
				aObj.put("id", ety.getModuleId());
				aObj.put("type", ety.getType());
				aObj.put("className", ety.getClassName());
				aObj.put("urlpath", ety.getUrlPath());
				aObj.put("title", ety.getTitle());
				
				JSONObject launcherObj = new JSONObject();
				launcherObj.put("iconCls", ety.getIconCls());
				launcherObj.put("shortcutIconCls", ety.getShortcutIconCls());
				launcherObj.put("text", ety.getText());
				launcherObj.put("tooltip", ety.getTooltip());
				aObj.put("launcher", launcherObj);
				
				JSONObject launcherPathsObj = new JSONObject();
				launcherPathsObj.put("startmenu", ety.getStartmenu());
				aObj.put("launcherPaths", launcherPathsObj);
				
				modulesArr.add(aObj);
			}
			
			userDataObj.put("modules", modulesArr);
			AjaxOut.responseText(response, userDataObj.toString());
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
}
